package com.wjc.wjc.dao;

import com.wjc.wjc.unity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

public interface StudentRepository extends JpaRepository<Student,Long> , JpaSpecificationExecutor <Student>{
    Student findBySnoAndPassword(String sno,String password);

    Student findBySno(String sno);


    @Transactional
    @Modifying
    @Query("update Student sc set sc.password = '000' where sc.id=?1")
    void resetPwd(Long id);

    @Transactional
    @Modifying
    @Query("update Student sc set sc.password = ?1 where sc.sno=?2")
    void updatePwd(String password,String sno);


    @Transactional
    @Modifying
    @Query("update Student sc set sc.sex = ?1, sc.birthDate=?2, sc.affiliation=?3, sc.address=?4 where sc.sno=?5")
    void updateInfor(String sex, String birthDate, String affiliation, String address,String sno);
}
